﻿using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for OutputManager
/// </summary>
public class OutputManager
{
    Warning[] warnings;
    string[] streamids;
    string mimeType;
    string encoding;
    string filenameExtension;
    Microsoft.Reporting.WebForms.LocalReport lr;

	public OutputManager(String url)
	{
        lr = new Microsoft.Reporting.WebForms.LocalReport();
        lr.ReportPath = url;
        lr.EnableExternalImages = true;
	}

    public void addParameter(String parameterName, String value)
    {
        ReportParameter tempParameter = new ReportParameter();
        tempParameter.Values.Add(value);
        tempParameter.Name = parameterName;
        lr.SetParameters(tempParameter);
    }

    public void createTicket(String url, string extension, string extra = "")
    {
        byte[] bytes = lr.Render(
        "PDF", null, out mimeType, out encoding, out filenameExtension,
        out streamids, out warnings);

        using (FileStream fs = new FileStream(url + extra + extension, FileMode.Create))
        {
            fs.Write(bytes, 0, bytes.Length);
        }
    }


}